package gui.splash;

import java.io.IOException;
import javax.microedition.lcdui.*;
import recados.Recados;

public class Splash extends Canvas {

    private final Recados midlet;
    private Image splash;
    private boolean dissmissed = false;

    public Splash(Recados midlet) {
        this.midlet = midlet;

        try {
            splash = Image.createImage("/gui/splash/logo.png");
        } catch (IOException ex) {
        }

        setFullScreenMode(true);
    }

    public void play() {

        try {
            Thread.sleep(2500);
        } catch (InterruptedException ex) {
            Recados.setCurrent(new Alert("Erro", "Splash Interrompido", null, AlertType.ERROR));
        }

        if (!dissmissed) {
            Recados.setCurrent(midlet.getLogin());
            dissmissed = true;
        }
    }

    protected void paint(Graphics g) {
        g.setColor(0);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.drawImage(splash, (getWidth() - splash.getWidth()) / 2, (getHeight() - splash.getHeight()) / 2, 0);
    }

    public void keyPressed(int keyCode) {
        if (!dissmissed) {
            Recados.setCurrent(midlet.getLogin());
            dissmissed = true;
        }
    }

    public void pointerPressed(int x, int y) {
        if (!dissmissed) {
            Recados.setCurrent(midlet.getLogin());
            dissmissed = true;
        }
    }
}
